/**
 * @version 1.0
 * @created 06 December 2010
 *
 * ListMyBidsController
 *
 * Copyright @ 2010 by CES
 * All Rights Reserved.
 * CES CONFIDENTIAL AND TRADE SECRET
 * 
 */
package com.ces.knacky.controller.tools;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ces.knacky.framework.controller.ListController;
import com.ces.knacky.model.Bid;
import com.ces.knacky.model.UserTable;
import com.ces.knacky.services.AuctionService;

/**
 * This controller displays the list of bids placed/approved/canceled by the logged-in user.
 * @author shivangi_walvekar
 *
 */
@Controller
public class ListMyBidsController extends ListController<Bid>{
	
	@Autowired
	private AuctionService auctionService;
	
	private Integer loggedInUserId;
	/**
	 * @return list of bids 
	 */
	@RequestMapping("/listMyBids.htm")
	public String execute(){
		
		/* TODO - This is temporary. Once the acegi framework is in place we can get the logged-in
		 *  userId from session and use it.*/
		UserTable user = (UserTable)commonService.findFirstByDescription(
				UserTable.class, SecurityContextHolder.getContext().getAuthentication().getName());
		listEntity = auctionService.loadMyBids(user.getId());
		if(listEntity != null){
			for (Bid bid : listEntity) {
				System.out.println("bid= "+bid.getId());
			}
		}
		return "listMyBids";
	}
	
	/**
	 *  @return loggedInUserId - persistent id of the logged-in user
	 */
	public Integer getLoggedInUserId() {
		return loggedInUserId;
	}


	/**
	 * @param loggedInUserId - persistent id of the logged-in user
	 */	
	public void setLoggedInUserId(Integer loggedInUserId) {
		this.loggedInUserId = loggedInUserId;
	}

}
